import 'package:sainbainu/common/apis/user_api.dart';

import 'package:sainbainu/common/models/request/pager_request.dart';
import 'package:sainbainu/common/models/response/content_response.dart';

import 'package:sainbainu/common/models/response/follow_fans_response.dart';
import 'package:sainbainu/common/models/response/my_comment_response.dart';
import 'package:sainbainu/common/models/response/other_user_info.dart';
import 'package:sainbainu/common/models/response/user_info.dart';
import 'package:sainbainu/common/models/response/user_profile_response.dart';

class UserRepository {
  final UserApi _userApi;

  UserRepository(this._userApi);

  /// 关注列表
  Future<FollowFansResponse> followList(PagerRequest pagerRequest) async {
    var res = await _userApi.followList(pagerRequest.toJson());
    return FollowFansResponse.fromJson(res);
  }

  /// 粉丝列表
  Future<FollowFansResponse> fansList(PagerRequest pagerRequest) async {
    var res = await _userApi.fansList(pagerRequest.toJson());
    return FollowFansResponse.fromJson(res);
  }

  /// 新增粉丝列表
  Future<FollowFansResponse> newFansList(PagerRequest pagerRequest) async {
    var res = await _userApi.newFansList(pagerRequest.toJson());
    return FollowFansResponse.fromJson(res);
  }

  /// 关注
  Future<Map<String, dynamic>> follow(int followCustomerId) async {
    var res = await _userApi.follow({'followCustomerId': followCustomerId});
    return res;
  }

  /// 取消关注
  Future<Map<String, dynamic>> unFollow(int followCustomerId) async {
    var res = await _userApi.unFollow({'followCustomerId': followCustomerId});
    return res;
  }

  /// 用户详情
  Future<UserInfoResponse> userInfo() async {
    var res = await _userApi.userInfo();
    return UserInfoResponse.fromJson(res['data']);
  }

  /// 用户资料
  Future<UserProfileResponse> userProfile() async {
    var res = await _userApi.userProfile();
    return UserProfileResponse.fromJson(res['data']);
  }

  /// 修改性别
  Future<Map<String, dynamic>> setGender(int gender) async {
    var res = await _userApi.setGender({'gender': gender});
    return res;
  }

  /// 修改生日
  Future<Map<String, dynamic>> setBirthday(String birthday) async {
    var res = await _userApi.setBirthday({'birthday': birthday});
    return res;
  }

  /// 修改昵称
  Future<Map<String, dynamic>> setNickname(String nickname) async {
    var res = await _userApi.setNickname({'nickname': nickname});
    return res;
  }

  /// 修改封面
  Future<Map<String, dynamic>> setCover(String cover) async {
    var res = await _userApi.setCover({'cover': cover});
    return res;
  }

  /// 修改头像
  Future<Map<String, dynamic>> setAvatar(String avatar) async {
    var res = await _userApi.setAvatar({'avatar': avatar});
    return res;
  }

  /// 修改简介
  Future<Map<String, dynamic>> setIntro(String intro) async {
    var res = await _userApi.setIntro({'intro': intro});
    return res;
  }

  /// 修改所在地
  Future<Map<String, dynamic>> setAddress(String seatAddress) async {
    var res = await _userApi.setAddress({'seatAddress': seatAddress});
    return res;
  }

  /// 修改唯一号
  Future<Map<String, dynamic>> setUniqueNo(String uniqueNo) async {
    var res = await _userApi.setUniqueNo({'uniqueNo': uniqueNo});
    return res;
  }

  /// 修改职业
  Future<Map<String, dynamic>> setJob(String job) async {
    var res = await _userApi.setJob({'job': job});
    return res;
  }

  /// 我的评论列表
  Future<MyCommentListResponse> myCommentList(PagerRequest pagerRequest) async {
    var res = await _userApi.myCommentList(pagerRequest.toJson());
    return MyCommentListResponse.fromJson(res);
  }

  /// 某个用户详情
  Future<OtherUserInfoResponse> otherUserInfo(int customerId) async {
    var res = await _userApi.otherUserInfo({'customerId': customerId});
    return OtherUserInfoResponse.fromJson(res['data']);
  }

  /// 某个用户的帖子列表
  Future<ContentListResponse> otherUserContentList(
    int customerId,
    PagerRequest pagerRequest,
  ) async {
    Map<String, dynamic> params = pagerRequest.toJson();
    params['customerId'] = customerId;
    var res = await _userApi.otherUserContentList(params);
    return ContentListResponse.fromJson(res);
  }

  /// 某个用户的点赞列表
  Future<ContentListResponse> otherUserLikeList(
    int customerId,
    PagerRequest pagerRequest,
  ) async {
    Map<String, dynamic> params = pagerRequest.toJson();
    params['customerId'] = customerId;
    var res = await _userApi.otherUserLikeList(params);
    return ContentListResponse.fromJson(res);
  }

  /// 某个用户的评论列表
  Future<MyCommentListResponse> otherUserCommentList(
    int customerId,
    PagerRequest pagerRequest,
  ) async {
    Map<String, dynamic> params = pagerRequest.toJson();
    params['customerId'] = customerId;
    var res = await _userApi.otherUserCommentList(params);
    return MyCommentListResponse.fromJson(res);
  }
}
